import axios from 'axios'
import { getUser } from '@/utils/store'
import JSONbig from 'json-bigint'
const instance = axios.create({
  // 所有接口地址都等于baseUrl拼接上 方法调用时候url地址
  baseURL: 'http://ttapi.research.itcast.cn/',
  transformResponse: [function (data) {
    // console.log(data)
    try {
      // console.log(JSONbig.parse(data))
      return JSONbig.parse(data)
    } catch (error) {
      console.log('JSONbig转换出错', error)
      return data
    }
  }]
})
instance.interceptors.request.use(function (config) {
  const userInfo = getUser()
  if (userInfo) {
    config.headers.Authorization = `Bearer ${userInfo}`
  }
  return config
}, function (error) {
  return Promise.reject(error)
})
// const str = '{ "id": 1253585734669959168 }'
// console.log(JSON.parse(str).id.toString()) // 1253585734669959200
// console.log(JSONbig.parse(str).id.toString()) // 1253585734669959168
// instance = 添加了baseUrl属性的axios
export default instance
